Page({
  data: {
    tabs: [
      {name: '待评价'},
      {name: '可追评'},
      {name: '已评价'}
    ],
    //tabIndex: 0,
    //bgColor: 'linear-gradient(90deg, rgb(252, 30, 82), rgb(255, 118, 38))',
    scrollTop: 0,
    pageIndex: 1,
    productList: [[], [], []],
    noMore: false,
  },
  onLoad: function (options) {
    this.setData({
      id: options.id || 0,
      tabIndex: options.evaluate || 0
    }, () => {
      if (this.data.noMore) return;
      let api = (this.data.id > 0 ? 'evaluate.products' : 'my');
      // 订单详情
      wx.util.request(`order.${api}`, {
        query: `order_id=${this.data.id}&is_evaluate=${this.data.tabIndex}`,
        body: {
          page: this.data.pageIndex,
          synthesize_status: 3
        }
      }).then(res => {
        let data = this.data,
            list = data.productList,
            first = [],
            again = [],
            complete = [];
        for (let item of res) {
          if (data.id > 0) {
            //list.push(item);
            if (item.is_evaluate == 0) first.push(item);
            else if (item.is_evaluate == 1) again.push(item);
            else complete.push(item);
            continue;
          }
          for (let p of item.product) {
            //list.push(p);
            if (p.is_evaluate == 0) first.push(p);
            else if (item.is_evaluate == 1) again.push(p);
            else complete.push(p);
          }
        }
        this.setData({
          productList: [list[0].concat(first), list[1].concat(again), list[1].concat(complete)],
          noMore: (this.data.id > 0 || res.length < 10),
          pageIndex: this.data.pageIndex + 1
        });
      }).catch(err => {
        console.log(err);
      });
    });
  },
  onPageScroll: function (e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },
  change: function (e) {
    this.setData({
      tabIndex: e.detail.index
    });
  },
  evaluate: function (e) {
    let product = this.data.productList[this.data.tabIndex][e.currentTarget.dataset.index];
    wx.navigateTo({
      url: `submit?id=${product.id}&img=${product.product_picture}&evaluate=${product.is_evaluate}`,
    });
  },
  detail: function (e) {
    wx.util.toast('功能开发中~');
    /*wx.navigateTo({
      url: `detail?id=${e.currentTarget.dataset.id}`,
    });*/
  }
})